<html>

<head>
    <meta name="description" content="JavaScript基础- 数据类型🔨--Alger的博客">
    <meta name="keywords"
        content="Alger,Alger的博客,Alger's blog,alger,alger的博客,html,css,vue,刘俊杰的博客,刘俊杰,liujunjie,Alger开发,Android,刘先生">

    <meta charset="utf-8" />
<meta name="description" content="" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<title>JavaScript基础- 数据类型🔨 | Alger&#39;s blog</title>

<link rel="shortcut icon" href="http://www.myalger.ml/favicon.ico?v=1602725656399">

<link href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="http://www.myalger.ml/styles/main.css">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/css/bootstrap.min.css">

<script src="https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets/highlight.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dockerfile.min.js"></script>
<script src="https://cdn.bootcss.com/highlight.js/9.15.10/languages/dart.min.js"></script>

<script src="https://cdn.jsdelivr.net/npm/moment@2.27.0/moment.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.5.0/dist/js/bootstrap.min.js"></script>
<!-- DEMO JS -->
<!--<script src="media/scripts/index.js"></script>-->


    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.12.0/dist/katex.css">
</head>

<body>
    <div class="main gt-bg-theme-color-first">
        <nav class="navbar navbar-expand-lg">
    <div class="navbar-brand">
        <img class="user-avatar" src="/images/avatar.png" alt="头像">
        <div class="site-name gt-c-content-color-first">
            Alger&#39;s blog
        </div>
    </div>
    <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
        <i class="fas fa-bars gt-c-content-color-first" style="font-size: 18px"></i>
    </button>
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <div class="navbar-nav mr-auto" style="text-align: center">
            
                <div class="nav-item">
                    
                        <a href="/" class="menu gt-a-link">
                            首页
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/archives" class="menu gt-a-link">
                            归档
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="/tags" class="menu gt-a-link">
                            标签
                        </a>
                    
                </div>
            
                <div class="nav-item">
                    
                        <a href="http://www.myalger.ml/about" class="menu gt-a-link">
                            关于
                        </a>
                    
                </div>
            
        </div>
        <div style="text-align: center">
            <form id="gridea-search-form" style="position: relative" data-update="1602725656399" action="/search/index.html">
                <input class="search-input" autocomplete="off" spellcheck="false" name="q" placeholder="搜索文章" />
                <i class="fas fa-search gt-c-content-color-first" style="position: absolute; top: 9px; left: 10px;"></i>
            </form>
        </div>
    </div>
</nav>

        <div class="post-container">
            <div class="post-detail gt-bg-theme-color-second">
                <article class="gt-post-content">
                    <h2 class="post-title">
                        JavaScript基础- 数据类型🔨
                    </h2>
                    <div class="post-info">
                        <time class="post-time gt-c-content-color-first">
                            · 2020-03-13 ·
                        </time>
                        
                        <a href="http://www.myalger.ml/He-D_m5QM/" class="post-tags">
                            # JavaScript
                        </a>
                        
                    </div>
                    <div class="post-content">
                        <p>ES5中有六种数据类型<br>
js中的数据类型为字面变量 以它的值来定义数据类型</p>
<!-- more -->
<p><strong>ES5中有六种数据类型</strong></p>
<ol>
<li>string</li>
<li>Number</li>
<li>Boolean</li>
<li>Null</li>
<li>undefined</li>
<li>Symbol ES6</li>
<li>Object</li>
</ol>
<p><strong>js中的数据类型为字面变量   以它的值来定义数据类型</strong></p>
<ol>
<li>
<p>字符串的定义，可以使用单引号也可以使用双引号 但是不能混用，可以使用转义字符</p>
<pre><code class="language-html">&lt;script&gt;
	let a = &quot;hello world&quot;;
    a = 'hello world';
    a=&quot;我说：'刘俊杰很帅'&quot;;
    a='我说：&quot;刘俊杰很帅&quot;'
    a=&quot;我说：\&quot;刘俊杰很帅\&quot;&quot;
&lt;/script&gt;
</code></pre>
</li>
<li>
<p>数值型的定义</p>
<p>在js中所有的数字都是<strong>Number类型</strong> 包含整数和小数</p>
<pre><code class="language-html"> &lt;script&gt;
     let a = 123;
     a = 123.12;
     console.log(a);
&lt;/script&gt;
</code></pre>
<p>有最大值和最小值，还有一个无穷大的值 <strong>Infinity</strong></p>
<p>还有<strong>不能运算的类型</strong>NaN（如0/0）或者字符串运算</p>
<p><strong>typeof运算符可以检查一个变量或数值的类型</strong></p>
<p><strong>进行浮点运算会出现误差     不建议用来进行金钱运算</strong></p>
<p><strong>进制转换</strong> 0x开头表示八进制   0b表示二进制</p>
</li>
<li>
<p>布尔数据类型boolean</p>
<p>逻辑判断 <strong>true</strong>       <strong>false</strong></p>
</li>
<li>
<p>null类型</p>
<p><strong>null类型只有一个值null</strong></p>
</li>
<li>
<p>undefined数据类型</p>
<p><strong>表示一个数值没有被赋值</strong></p>
</li>
</ol>
<p><strong>强制类型装换</strong>可以把一种类型转换成另一种</p>
<p><strong>1. 调用方法   toString()</strong>    有局限性</p>
<pre><code class="language-html">&lt;script&gt;
    let a = 123;
    console.log(a.toString());
&lt;/script&gt;
</code></pre>
<p>**2. 调用String()函数 **    可以转换所有</p>
<pre><code class="language-html">&lt;script&gt;
    let a = 123;
    console.log(String(a));
&lt;/script&gt;
</code></pre>
<p><strong>3. Number()函数可以把字符串转换为数字</strong></p>
<p>只能转换纯数字字符串，空格和空转换为0</p>
<pre><code class="language-html">&lt;script&gt;
    let a = &quot;123546&quot;;
&lt;/script&gt;
</code></pre>
<p><strong>4. parseInt() 和 parseFloat(方法可以忽略字符自把前面的数字转换</strong></p>
<p>两个方法转换非字符串类型会将其先转换为字符串再取数字</p>
<p>parseInt()可以用来间接取整</p>
<pre><code class="language-html">&lt;script&gt;
	let a = &quot;123546.456fsdsf&quot;;
	//把整数部分取出来转换为整数
    console.log(parseInt(a));
    //把小数部分取出来转换为小数
    console.log(parseFloat(a));
&lt;/script&gt;
</code></pre>
<p><strong>5. 转换成Boolean类型 使用 Boolean()函数</strong></p>
<p><strong>将数值类型转换为boolean时</strong>  除了<strong>0</strong>和<strong>NaN</strong>为<strong>false</strong>其他都是<strong>true</strong></p>
<p><strong>将字符串转换为boolean时</strong>   除了<strong>空字符串</strong>为<strong>false</strong>其他都转换为<strong>true</strong>包括空格</p>
<p><strong>将null转换为Boolean时</strong>     只有一个值为<strong>false</strong></p>
<p><strong>将undefined转换为boolean时</strong>   只有一个值为<strong>false</strong></p>
<p><strong>将对象Object转换为boolean时</strong>    只要引用不为空都是<strong>true</strong></p>

                    </div>
                </article>
            </div>

            
            <div class="next-post">
                <div class="next gt-c-content-color-first">下一篇</div>
                <a href="http://www.myalger.ml/JAB_FEMKG/" class="post-title gt-a-link">
                    JavaScript----Vue.js基础学习 🚀
                </a>
            </div>
            

            
            <span id="/MFE_EFMK/" class="leancloud_visitors" data-flag-title="JavaScript基础- 数据类型🔨">
                <em class="post-meta-item-text">阅读量 </em>
                <i class="leancloud-visitors-count">0</i>
            </span>
            

            

            
            <script src='https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js'></script>

<style>
	div#vcomments{
		width:100%;
		max-width: 1000px;
		padding: 2.5%
	}
</style>


	<div id="vcomments"></div>

<script>
	new Valine({
		el: '#vcomments',
		appId: 'zSod8O6f9ppLFYxB5PgGNotJ-gzGzoHsz',
		appKey: 'zPFYmL2RAeARE6sTWFnHfJg7',
		avatar: 'retro',
		pageSize: 10,
		recordIp: true,
		placeholder: 'Just Go Go',
		visitor: true,
	});
</script>

            

            <div class="site-footer gt-c-content-color-first">
    <div class="slogan gt-c-content-color-first">春风得意马蹄疾,一日看尽长安花.
</div>
    <div class="social-container">
        
            
        
            
        
            
        
            
        
            
        
            
        
    </div>
    <div class="footer-info">
        Powered by <a href="https://github.com/getgridea/gridea" target="_blank">Gridea</a>
    </div>
    <div>
        Theme by <a href="https://imhanjie.com/" target="_blank">imhanjie</a>, Powered by <a
                href="https://github.com/getgridea/gridea" target="_blank">Gridea | <a href="http://www.myalger.ml/atom.xml" target="_blank">RSS</a></a>
    </div>
</div>

<script>
  hljs.initHighlightingOnLoad()
</script>

        </div>
    </div>
</body>

</html>